#ifndef __TYPEDEF_H__
#define __TYPEDEF_H__

#ifndef  LIB_BASIC             // STM32、LIUNX都带有标准C库
#include <stddef.h>            // NULL定义文件
#include <stdio.h>             // 输入输出基本库
#include <string.h>            // 字符输出
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>

//=====================基本函数定义================
#else   // 如果没有标准C库则自己定义
#define    strncpy(dest, src, n) \
do \
{my_strncpy(dest, src, n);}while(0)


#define    memset(dest, ch, n) \
do \
{my_memset(dest, ch, n);}while(0)
 

#define    memcpy(dest, src, n) \
do \
{my_memcpy(dest, src, n);}while(0) 

#define    strlen(src) (my_strlen(src))
#define    NULL        ((void *)0)
#endif



// 平台选择
#define STM32                        0xAE
#define LINUX                        0xAF
#define SYSTEM                       LINUX

#if (SYSTEM == LINUX)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif


#if (SYSTEM == LINUX)
#define    debug(format, ...) \
	printf (format, ##__VA_ARGS__)
	//printf("FILE: "__FILE__", LINE: %d: "format"\n", __LINE__, ##__VA_ARGS__)
#else
#define    debug(format,...) \
	my_printf(format, ##__VA_ARGS__)
#endif


#if (SYSTEM == LINUX)
#define    app_write(fd, buffer, len) (write(fd, buffer, len))
#else
#define    app_write(fd, buffer, len) (my_write(fd, buffer, len))
#endif 

#if (SYSTEM == LINUX)
#define    app_read(fd, buffer, len) (read(fd, buffer, len))
#else
#define    app_read(fd, buffer, len) (my_read(fd, buffer, len))
#endif

#define RET_ERR                     -1
#define RET_OK                       0

#define __DEBUG_APP_O0__             0x00
#define __DEBUG_APP_O1__             0x01
#define __DEBUG_APP_O2__             0x02
#define __DEBUG_APP_O3__             0x03


typedef    char                      s8; 
typedef    const char               cs8;
typedef    unsigned char             u8;
typedef    const unsigned char      cu8;
typedef    short                    s16;
typedef    const short             cs16;
typedef    unsigned short           u16;
typedef    const unsigned short    cu16;
typedef    int                      s32;
typedef    const int               cs32;
typedef    unsigned int             u32;
typedef    const unsigned int      cu32;
typedef    long                     s64;
typedef    const long              cs64;
typedef    unsigned long            u64;
typedef    const unsigned long     cu64;

s8*     my_strncpy(s8 *dest, cs8 *src, u32 len) ;
void*	my_memset(void *dest, u8 ch, u32 len);
void*	my_memcpy(void *dest, void *src, u32 len) ;
u32     my_strlen(cs8 *src);
s32 	my_read(u8 fd, void *buff, s32 len);
s32	    my_write(u8 fd, void *buff, s32 len);
s32 	my_printf(const char* fmt, ...); 
s32 	my_errno_get(void);
void 	my_errno_set(s32 errno);


//====================================end=====================================
#endif

